package com.kaochong.xcx.web.controller;

import com.kaochong.xcx.pojo.vo.BookCategoryVO;
import com.kaochong.xcx.service.WordBookService;
import com.kaochong.xcx.utils.response.ResponseUtils;
import com.kaochong.xcx.utils.response.ResultVO;
import com.kaochong.xcx.web.aspect.CurrentUser;
import com.kaochong.xcx.web.controller.base.BasicController;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

import lombok.extern.slf4j.Slf4j;

/**
 * @author han
 * @date 2018-07-13 15:25
 */
@RestController
@RequestMapping("/recite")
@Slf4j
public class CategoryController extends BasicController {
	
	@Autowired
	WordBookService wordBookService;
	
	@GetMapping("/category/list")
	public ResultVO category(Map<String, Object> map) {
		List<BookCategoryVO> categories = wordBookService.findBookCategory();
		map.put("categories", categories);
		return ResponseUtils.success(map);
	}
	
	@GetMapping("/wordbook/findByCategory")
	public ResultVO findByCategory(@RequestParam(value = "category") Integer categoryId,
	                               Map<String, Object> map) {
		CurrentUser user = takeUser();
		map = wordBookService.findWordBookByCategoryId(user, categoryId);
		return ResponseUtils.success(map);
	}
}
